#!/usr/bin/env python

from Bio import SeqIO
import argparse
import sys
import os

parser = argparse.ArgumentParser(description="Parse nucleotide sequences from GenBank file into fasta file. For version info, run `bit-version`.")

required = parser.add_argument_group('required arguments')

required.add_argument("-i", "--input_gb", help='input Genbank file (e.g. "*.gbk", "*.gb", "*.gbff")', action="store", dest="input_gb", required=True)
parser.add_argument("-o", "--output_fasta", help='Output fasta file (default: "genbank.fa")', action="store", dest="output_fasta", default="genbank.fa")

if len(sys.argv)==1:
    parser.print_help(sys.stderr)
    sys.exit(0)
   
args = parser.parse_args()

input_gb = open(args.input_gb, "r")

output = open(args.output_fasta, "w")

recs = [rec for rec in SeqIO.parse(input_gb, "genbank")]

for rec in recs:
    output.write(">" + rec.name  + "\n" + str(rec.seq) + "\n")

input_gb.close()
output.close()
